import { defineStore } from "pinia";
import { store } from "@/store";
interface UserState {
  userInfo: any,
  access_token: string,
  refresh_token: string,
}

export const useUserStore = defineStore("user", {
  state: (): UserState => {
    return {
      userInfo: undefined,
      access_token: "",
      refresh_token: "",
    }
  },
  getters: {
    getUserInfo: (state: any) => {
      return state.userInfo
    },
    getAccessToken: (state: any) => {
      return state.access_token
    },
    getRefreshToken: (state: any) => {
      return state.refresh_token
    }
  },
  actions: {
    setUserInfo(userInfo: any) {
      this.userInfo = userInfo
    },
    setAccessToken(token: string) {
      this.access_token = token
    },
    setRefreshToken(token: string) {
      this.refresh_token = token
    },
    reset() {
      this.userInfo = undefined
      this.refresh_token = ''
      this.access_token = ''
    },
    LoginOut() {
      this.reset()
    }
  },
  persist: true
})

export const useUserStoreWithOut = () => {
  return useUserStore(store)
}